package oj;

/**
 * @author 郝文雪
 * @date 2022/8/18 11:40
 * @Description Test
 */
public class LC14 {
    public String longestCommonPrefix(String[] strs) {
        if(strs==null || strs.length==0) return "";
        String pre=strs[0];
        for(int i=1;i<strs.length;i++){
            pre=longestCommonPrefix(strs[i],pre);
            if(pre.length()==0){
                break;
            }
        }
        return pre;
    }
    private String longestCommonPrefix(String str1,String str2) {
        int index=0;
        int len=Math.min(str1.length(),str2.length());
        while(index<len && str1.charAt(index)==str2.charAt(index)){
            index++;
        }
        return str1.substring(0,index);
    }
}
